<style src="./index.scss" lang="scss" scoped rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
export default {
  mixins: [Vue.prototype.$vFN.Mixins.Base],
  computed: {},
  data() {
    return {
      type: 0,
      title: "",
      // 窗口显示
      boxVisible: false,
      // 物流列表
      logisticsOptions: [],

      form: {
        list: [],
      },

      newOrderItemLst: [], //改造后的商品数组

      multipleSelection: [], //选中了哪些商品
    };
  },
  methods: {
    packageTitle(item_) {
      return `包裹 共${item_.productNum}个商品`;
    },

    // 验证
    validate() {
      return new Promise((resolve, reject) => {
        this.$refs["editForm"].validate((valid) => {
          valid ? resolve(true) : resolve(false);
        });
      });
    },

    async getUnpackData(orderId) {
      let res = await this.$vFN.Http.post(
        {
          url: "mall-site-portal/order/getUnpackDelivery",
          data: {
            orderId,
          },
        },
        window
      );

      if (res._ok) {
        this.form.list = res.data;
      }
    },

    // 提交
    async submit() {
      if (!(await this.validate())) {
        return;
      }

      let list_ = this.form.list.map((el_) => {
        return {
          isNeedLogistics: el_.isNeedLogistics,
          deliveryNo: el_.deliveryNo,
          deliveryId: el_.id,
          companyId: el_.companyId,
        };
      });

      let res = await this.$vFN.Http.post(
        {
          url: "mall-site-portal/order/modifyUnpackDelivery",
          data: {
            orderId: this.item.id,
            unpackModifyItemLst: list_,
          },
        },
        window
      );

      if (res._ok) {
        this.$vFN.Tools.messageSuccess("操作成功");
        this.editBoxClose();
        this.onSuccess();
      }
    },

    // 成功回调
    onSuccess() {},
    // 取消回调
    onCancel() {},
    // 失败回调
    onError() {},
    // 关闭窗口
    editBoxClose() {
      this.boxVisible = false;
    },
    // 取消
    editBoxCancel() {
      this.editBoxClose();
    },

    show(e, item) {
      console.log(e, item);
    },
  },
  watch: {},
  async mounted() {
    // 数据源 物流列表
    this.logisticsOptions = await this.$vFN.Tools.getSelectListSource(
      {
        url: "mall-site-portal/order/getLogisticsCompany",
        format: false,
      },
      window
    );

    if (this.type == 0) {
      this.title = "发货";
    } else if (this.type == 1) {
      this.title = "修改快递";

      if (this.item.isUnpack) {
        this.getUnpackData(this.item.id);
      }
    }

    this.boxVisible = true;
  },
  beforeCreate() {},
};
</script>